<?xml version="1.0"?>

<st-source>
<time-stamp>From VisualWorks® NonCommercial, 7.6 of March 3, 2008 on April 7, 2009 at 2:54:39 pm</time-stamp>


<class>
<name>CCSAppModel</name>
<environment>SupplyChain</environment>
<super>UI.ApplicationModel</super>
<private>false</private>
<indexed-type>none</indexed-type>
<inst-vars>ccs retailerList supplierList </inst-vars>
<class-inst-vars></class-inst-vars>
<imports></imports>
<category></category>
<attributes>
<package>SupplyChain</package>
</attributes>
</class>

<!-- -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -   -->


<methods>
<class-id>SupplyChain.CCSAppModel class</class-id> <category>interface specs</category>

<body package="SupplyChain" selector="windowSpec">windowSpec
	"Tools.UIPainter new openOnClass: self andSelector: #windowSpec"

	&lt;resource: #canvas&gt;
	^#(#{UI.FullSpec} 
		#window: 
		#(#{UI.WindowSpec} 
			#label: 'CCS Main GUI' 
			#bounds: #(#{Graphics.Rectangle} 640 512 1148 925 ) ) 
		#component: 
		#(#{UI.SpecCollection} 
			#collection: #(
				#(#{UI.LabelSpec} 
					#layout: #(#{Core.Point} 4 391 ) 
					#name: #CCSMainGUI 
					#label: 'CCS Main GUI' ) 
				#(#{UI.SequenceViewSpec} 
					#layout: #(#{Graphics.Rectangle} 11 58 201 264 ) 
					#name: #supplierList 
					#model: #supplierList 
					#useModifierKeys: true 
					#selectionType: #highlight ) 
				#(#{UI.ActionButtonSpec} 
					#layout: #(#{Graphics.Rectangle} 13 272 94 295 ) 
					#name: #addSupplier 
					#model: #addSupplier 
					#label: 'Add Supplier' 
					#defaultable: true ) 
				#(#{UI.ActionButtonSpec} 
					#layout: #(#{Graphics.Rectangle} 120 272 201 295 ) 
					#name: #deleteSupplier 
					#model: #deleteSupplier 
					#label: 'Delete Supplier' 
					#defaultable: true ) 
				#(#{UI.ActionButtonSpec} 
					#layout: #(#{Graphics.Rectangle} 218 179 298 203 ) 
					#name: #load 
					#model: #load 
					#label: 'Load' 
					#defaultable: true ) 
				#(#{UI.ActionButtonSpec} 
					#layout: #(#{Graphics.Rectangle} 219 212 300 235 ) 
					#name: #save 
					#model: #save 
					#label: 'Save ' 
					#defaultable: true ) 
				#(#{UI.SequenceViewSpec} 
					#layout: #(#{Graphics.Rectangle} 313 59 503 264 ) 
					#name: #retailerList 
					#model: #retailerList 
					#useModifierKeys: true 
					#selectionType: #highlight ) 
				#(#{UI.ActionButtonSpec} 
					#layout: #(#{Graphics.Rectangle} 422 273 503 295 ) 
					#name: #deleteRetailer 
					#model: #deleteRetailer 
					#label: 'Delete Retailer' 
					#defaultable: true ) 
				#(#{UI.ActionButtonSpec} 
					#layout: #(#{Graphics.Rectangle} 217 149 298 172 ) 
					#name: #viewReport 
					#model: #viewReport 
					#label: 'View Reports' 
					#defaultable: true ) 
				#(#{UI.LabelSpec} 
					#layout: #(#{Core.Point} 14 32 ) 
					#name: #SupplierList 
					#label: 'Supplier List' ) 
				#(#{UI.LabelSpec} 
					#layout: #(#{Core.Point} 314 33 ) 
					#name: #RetailerList 
					#label: 'Retailer List' ) 
				#(#{UI.ActionButtonSpec} 
					#layout: #(#{Graphics.Rectangle} 315 273 396 295 ) 
					#name: #addRetailer 
					#model: #addRetailer 
					#label: 'Add Retailer' 
					#defaultable: true ) 
				#(#{UI.ActionButtonSpec} 
					#layout: #(#{Graphics.Rectangle} 62 309 143 332 ) 
					#name: #supplierGUI 
					#model: #supplierGUI 
					#label: 'Open Supplier' 
					#defaultable: true ) 
				#(#{UI.ActionButtonSpec} 
					#layout: #(#{Graphics.Rectangle} 369 310 450 333 ) 
					#name: #retailerGUI 
					#model: #retailerGUI 
					#label: 'Open Retailer' 
					#defaultable: true ) ) ) )</body>
</methods>

<!-- -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -   -->


<comment>
<class-id>SupplyChain.CCSAppModel</class-id>
<body>GUI with list of retailers and suppliers. You can add/delete suppliers/retailers and view inventory

Instance Variables:
	ccs &lt;CCS&gt; A CCS
	retailerList	&lt;SelectionInList&gt;	list of retailers
	supplierList	&lt;SelectionInList&gt;	description of supplierList

</body>
</comment>

<methods>
<class-id>SupplyChain.CCSAppModel</class-id> <category>actions</category>

<body package="SupplyChain" selector="addRetailer">addRetailer
	"Adds a retailer to the list of retailers"
	|t1 t2 t3 t4|

	t2 := Dialog request: 'Retailer name' initialAnswer: ' '.
	(t2 = '') ifFalse:[
		t3 := Dialog request: 'Retailer location' initialAnswer: ' '.
			(t3= '') ifFalse:[
				t4 := Dialog request: 'Retailer number' initialAnswer: ' '.
					(t4 = '') ifFalse:[
						t1 := Retailer new.
						t1 name: t2.
						t1 location: t3.
						t1 number: t4.
						ccs addRetailer: t1.
						ccs changed: #retailers.].].].

	^self.</body>

<body package="SupplyChain" selector="addSupplier">addSupplier
	"Adds a supplier to the list of suppliers"
	|t1 t2 t3 t4|

	t2 := Dialog request: 'Supplier name' initialAnswer: ' '.
	(t2 = '') ifFalse:[
		t3 := Dialog request: 'Supplier location' initialAnswer: ' '.
			(t3= '') ifFalse:[
				t4 := Dialog request: 'Supplier number' initialAnswer: ' '.
					(t4 = '') ifFalse:[
						t1 := Supplier new.
						t1 name: t2.
						t1 location: t3.
						t1 number: t4.
						ccs addSupplier: t1.
						ccs changed: #suppliers.].].].

	

	^self.</body>

<body package="SupplyChain" selector="deleteRetailer">deleteRetailer
	"Deletes the selected retailer from the list of retailers"
	retailerList selection notNil ifTrue:[(ccs retailers) remove: (retailerList selection)].
	ccs changed: #retailers.
	^self</body>

<body package="SupplyChain" selector="deleteSupplier">deleteSupplier
	"Deletes the selected supplier from the list of suppliers"
	supplierList selection notNil ifTrue:[(ccs suppliers) remove: (supplierList selection)].
	ccs changed: #suppliers.
	^self</body>

<body package="SupplyChain" selector="load">load
	"Load a previous state"
	|boss filename array newCCS|
	filename := Dialog requestFileName: 'Open CCS'.
	(filename = '') ifFalse:[
		boss := BinaryObjectStorage onOldNoScan: filename asFilename readStream.
		[array := boss contents] ensure: [boss close].
		newCCS := array at: 1.
		self updateWith: newCCS.
		ccs changed: #suppliers.
		ccs changed: #retailers.
	].
	^self.</body>

<body package="SupplyChain" selector="retailerGUI">retailerGUI
	"Opens the gui for the selected retailer"
	|gui|
	retailerList selection notNil ifTrue:[
		gui := RetailerAppModel new.
		gui retailer: retailerList selection.
		gui open.
		"get data back."
		ccs changed: #retailers.].
	^self</body>

<body package="SupplyChain" selector="save">save
	"Save the current CCS"
	|boss filename newCCS|
	newCCS := ccs deepCopy.
	filename := Dialog requestFileName: 'Open CCS'.
	(filename = '') ifFalse:[
		boss := BinaryObjectStorage onNew: filename asFilename writeStream.
		[boss nextPut: newCCS ] ensure: [boss close].
	].
	^self.</body>

<body package="SupplyChain" selector="supplierGUI">supplierGUI
	"Opens the gui for the selected supplier"
	|gui|
	supplierList selection notNil ifTrue:[
		gui := SupplierAppModel new.
		gui model: supplierList selection.
		gui open.
		"get data back."
		ccs changed: #suppliers.].
	^self</body>

<body package="SupplyChain" selector="updateWith:">updateWith: aCCS
	"Used with BOSS loading to update a newly loaded class instance"
	ccs retailers size timesRepeat: [ ccs retailers removeFirst ].
	ccs suppliers size timesRepeat: [ ccs suppliers removeFirst ].
	aCCS retailers do: [ :r | ccs addRetailer: r.].
	aCCS suppliers do: [ :s | ccs addSupplier: s.].
	^self.</body>

<body package="SupplyChain" selector="viewReport">viewReport
	"Allows the user to view the three reports"
	| answer report|
	answer := Dialog choose: 'Which report would you like to view?'
	                   fromList: #('Price Volatility' 'Emergency Order' 'Supplier Quantity')
	                   values: #(#price #order #quantity)
                         lines: 3
                         cancel: [nil].
	answer isNil ifFalse:[
		answer = #quantity ifTrue:[ 
			report := SupplierQuantityReport new.
			report suppliers: ccs suppliers.
			report retailers: ccs retailers.
			report open.].
		].
	^self</body>
</methods>

<methods>
<class-id>SupplyChain.CCSAppModel</class-id> <category>aspects</category>

<body package="SupplyChain" selector="retailerList">retailerList
	"This method was generated by UIDefiner.  Any edits made here
	may be lost whenever methods are automatically defined.  The
	initialization provided below may have been preempted by an
	initialize method."

	^retailerList isNil
		ifTrue:
			[retailerList := SelectionInList new]
		ifFalse:
			[retailerList]</body>

<body package="SupplyChain" selector="supplierList">supplierList
	"This method was generated by UIDefiner.  Any edits made here
	may be lost whenever methods are automatically defined.  The
	initialization provided below may have been preempted by an
	initialize method."

	^supplierList isNil
		ifTrue:
			[supplierList := SelectionInList new]
		ifFalse:
			[supplierList]</body>
</methods>

<methods>
<class-id>SupplyChain.CCSAppModel</class-id> <category>initialize-release</category>

<body package="SupplyChain" selector="initialize">initialize
	super initialize.
	ccs := CCS new.
	(supplierList := SelectionInList new) listHolder: ((UI.AspectAdaptor subject: ccs sendsUpdates: true) forAspect: #suppliers).
	(retailerList := SelectionInList new) listHolder: ((UI.AspectAdaptor subject: ccs sendsUpdates: true) forAspect: #retailers).
	^self.</body>
</methods>

</st-source>
